package com.wyl.template.config.shiro;

import org.apache.shiro.session.SessionException;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.authc.LogoutFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @Auther: wyl
 * @Date: 2021/4/29
 * @Description: 自定义退出过滤器，取消 logout 拦截器默认情况下的重定向行为
 */
public class MyLogoutFilter extends LogoutFilter {

    private Logger log = LoggerFactory.getLogger(MyLogoutFilter.class);

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) {
        Subject subject = getSubject(request, response);
        try {
            subject.logout();
        } catch (SessionException ex) {
            log.error("Encountered session exception during logout.  This can generally safely be ignored.", ex);
        }
        return false;
    }
}
